package ability168

import (
    "log"
    "errors"
    "topsdk"
    "topsdk/ability168/request"
    "topsdk/ability168/response"
    "topsdk/util"
)

type Ability168 struct {
    Client *topsdk.TopClient
}

func NewAbility168(client *topsdk.TopClient) *Ability168{
    return &Ability168{client}
}

/*
    构建实例化应用
*/
func (ability *Ability168) TaobaoMiniappTemplateInstantiate(req *request.TaobaoMiniappTemplateInstantiateRequest,session string) (*response.TaobaoMiniappTemplateInstantiateResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.template.instantiate",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappTemplateInstantiateResponse{}
    if(err != nil){
        log.Println("taobaoMiniappTemplateInstantiate error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    （已废弃）更新实例化应用
*/
func (ability *Ability168) TaobaoMiniappTemplateUpdate(req *request.TaobaoMiniappTemplateUpdateRequest,session string) (*response.TaobaoMiniappTemplateUpdateResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.template.update",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappTemplateUpdateResponse{}
    if(err != nil){
        log.Println("taobaoMiniappTemplateUpdate error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    上线实例化应用
*/
func (ability *Ability168) TaobaoMiniappTemplateOnlineapp(req *request.TaobaoMiniappTemplateOnlineappRequest,session string) (*response.TaobaoMiniappTemplateOnlineappResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.template.onlineapp",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappTemplateOnlineappResponse{}
    if(err != nil){
        log.Println("taobaoMiniappTemplateOnlineapp error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    查询实例化应用版本
*/
func (ability *Ability168) TaobaoMiniappTemplateQueryapp(req *request.TaobaoMiniappTemplateQueryappRequest,session string) (*response.TaobaoMiniappTemplateQueryappResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.template.queryapp",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappTemplateQueryappResponse{}
    if(err != nil){
        log.Println("taobaoMiniappTemplateQueryapp error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    更新实例化应用
*/
func (ability *Ability168) TaobaoMiniappTemplateUpdateapp(req *request.TaobaoMiniappTemplateUpdateappRequest,session string) (*response.TaobaoMiniappTemplateUpdateappResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.template.updateapp",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappTemplateUpdateappResponse{}
    if(err != nil){
        log.Println("taobaoMiniappTemplateUpdateapp error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    小部件实例化版本更新
*/
func (ability *Ability168) TaobaoMiniappWidgetTemplateInstanceUpdate(req *request.TaobaoMiniappWidgetTemplateInstanceUpdateRequest,session string) (*response.TaobaoMiniappWidgetTemplateInstanceUpdateResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.widget.template.instance.update",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappWidgetTemplateInstanceUpdateResponse{}
    if(err != nil){
        log.Println("taobaoMiniappWidgetTemplateInstanceUpdate error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    小部件实例化版本查询
*/
func (ability *Ability168) TaobaoMiniappWidgetTemplateInstanceQuery(req *request.TaobaoMiniappWidgetTemplateInstanceQueryRequest,session string) (*response.TaobaoMiniappWidgetTemplateInstanceQueryResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.widget.template.instance.query",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappWidgetTemplateInstanceQueryResponse{}
    if(err != nil){
        log.Println("taobaoMiniappWidgetTemplateInstanceQuery error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    下线实例化应用
*/
func (ability *Ability168) TaobaoMiniappTemplateOfflineapp(req *request.TaobaoMiniappTemplateOfflineappRequest,session string) (*response.TaobaoMiniappTemplateOfflineappResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.template.offlineapp",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappTemplateOfflineappResponse{}
    if(err != nil){
        log.Println("taobaoMiniappTemplateOfflineapp error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    小部件实例化接口
*/
func (ability *Ability168) TaobaoMiniappWidgetTemplateInstantiate(req *request.TaobaoMiniappWidgetTemplateInstantiateRequest,session string) (*response.TaobaoMiniappWidgetTemplateInstantiateResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.widget.template.instantiate",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappWidgetTemplateInstantiateResponse{}
    if(err != nil){
        log.Println("taobaoMiniappWidgetTemplateInstantiate error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    回滚实例化应用
*/
func (ability *Ability168) TaobaoMiniappTemplateRollback(req *request.TaobaoMiniappTemplateRollbackRequest,session string) (*response.TaobaoMiniappTemplateRollbackResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniapp.template.rollback",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniappTemplateRollbackResponse{}
    if(err != nil){
        log.Println("taobaoMiniappTemplateRollback error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    （已废弃）构建实例化应用
*/
func (ability *Ability168) TaobaoMiniapppTemplateInstantiate(req *request.TaobaoMiniapppTemplateInstantiateRequest,session string) (*response.TaobaoMiniapppTemplateInstantiateResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability168 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.miniappp.template.instantiate",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoMiniapppTemplateInstantiateResponse{}
    if(err != nil){
        log.Println("taobaoMiniapppTemplateInstantiate error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
